/**
 * 数据源定义管理初始化
 */
var SdsStandDicCompDetail = {
    id: "sdsStandDicCompDetailTable",	//表格id
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
SdsStandDicCompDetail.initColumn = function () {
    var id = $('#id').val();
    var type = $('#type').val();
    if ('matched' === type) {
        column = [
            { title: '字典名称', field: 'dicName', align: 'center', valign: 'middle' },
            { title: '对照医嘱项', field: 'description', align: 'center', valign: 'middle' },
            { title: '对照医嘱通用名', field: 'drugCommonName', align: 'center', valign: 'middle' },
            { title: '状态', field: 'status', align: 'center', valign: 'middle',
                formatter:function (value, row, index) {
                    switch (value) {
                        case 0:
                            value = "未关联";
                            break;
                        case 1:
                            value = "已关联";
                            break;
                    }
                    return value;
                }
            }
        ];
    } else if ('fill' === type || 'rule' === type) {
        column = [
            { title: '字典名称', field: 'dicName', align: 'center', valign: 'middle' },
            { title: '使用次数', field: 'useNum', align: 'center', valign: 'middle' }
        ];
    }
    return column;
};

/**
 * 查询详情列表
 */
SdsStandDicCompDetail.search = function (type) {
    if (type === undefined) {
        type = $("#type").val();
    }
    if (type === 'matched') {
        type = $("#searchType").combobox("getValue");
        if (type === '') {
            type = 'all';
        }
    }
    var queryData = {};
    queryData['id'] = $("#id").val();
    queryData['type'] = type;
    queryData['description'] = $("#description").val();
    queryData['dicName'] = $("#dicName").val();
    SdsStandDicCompDetail.table.refresh({query: queryData, pageNumber: 1});
};

$(function () {
    if ($("#type").val() === 'rule' || $("#type").val() === 'fill') {
        $("#searchTypeTab").hide();
        $("#forDescription").hide();
    }
    var defaultColunms = SdsStandDicCompDetail.initColumn();
    var table = new BSTable(SdsStandDicCompDetail.id, Sys.backendPath + "/sds/sdsstanddiccompsta/dictMatchList", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(15);
    table.setQueryParams({ "id": $("#id").val(), "type": $("#type").val() });
    table.setSubHeight(-27);
    SdsStandDicCompDetail.table = table.init();
});